package edu.ilstu.mind.ise.ccp.logger;

public enum LoggerLevel {
	TRACE(6), DEBUG(5), INFO(4), WARN(3), ERROR(2), FATAL(1), NONE(0);

	private final int value;

	private LoggerLevel(int value) {
		this.value = value;
	}
	
	public boolean isLoggable(LoggerLevel loggerLevel) {
		return loggerLevel.value >= value;
	}
	
	public static LoggerLevel parse(String value) {
		if (value.equalsIgnoreCase("TRACE")) {
			return LoggerLevel.TRACE;
		} else if (value.equalsIgnoreCase("DEBUG")) {
			return LoggerLevel.DEBUG;
		} else if (value.equalsIgnoreCase("INFO")) {
			return LoggerLevel.INFO;
		} else if (value.equalsIgnoreCase("WARN")) {
			return LoggerLevel.WARN;
		} else if (value.equalsIgnoreCase("ERROR")) {
			return LoggerLevel.ERROR;
		} else if (value.equalsIgnoreCase("FATAL")) {
			return LoggerLevel.FATAL;
		} else if (value.equalsIgnoreCase("NONE")) {
			return LoggerLevel.NONE;
		} else {
			throw new IllegalArgumentException(value + " is not a valid logger level");
		}
	}
}
